package com.hxzy.controller;

import com.hxzy.common.enums.AckCode;
import com.hxzy.common.vo.R;
import com.hxzy.product.entity.Sku;
import com.hxzy.product.vo.SpuVO;
import com.hxzy.service.SkuService;
import com.hxzy.service.SpuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 产品查询
 *
 * @author tonneyyy
 */
@RestController
public class GoodsController {

    @Autowired
    private SkuService  skuService;

    @Autowired
    private SpuService spuService;
    /**
     * 根据spuid查询商品详情信息
     * @param spuId
     * @return
     */
    @GetMapping("/sku/spuid/{id}")
    public R<List<Sku>> querySkusBySpuId(@PathVariable("id") String spuId){
        List<Sku> list=this.skuService.querySkusBySpuId(spuId);

        return  R.okHasData(list);
    }

    /**
     * 根据spuid查询数据
     * @param id
     * @return
     */
    @GetMapping(value = "/spu/es/{id}")
    public R findSpuById(@PathVariable(value = "id") String id){
        SpuVO  spuVO= this.spuService.findSpuById(id);
        if(spuVO==null){
            return R.build(AckCode.NOT_FOUND_DATA);
        }
        return R.okHasData(spuVO);
    }

}
